﻿using Hangfire;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.BackgroundJobs.Hangfire;
using Volo.Abp.Modularity;
using Hangfire.MySql.Core;
using Microsoft.Extensions.Configuration;

namespace Cjj.Exam.Hangfire
{
    [DependsOn((
    //...other dependencies
    typeof(AbpBackgroundJobsHangfireModule) //Add the new module dependency
    ))]
    public class ExamHangfireModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();
            var hostingEnvironment = context.Services.GetHostingEnvironment();

            //... other configarations.

            ConfigureHangfire(context, configuration);



        }


        private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
        {
            context.Services.AddHangfire(config =>
            {
                config.UseStorage(new MySqlStorage(configuration.GetConnectionString("Default")));
            });
        }

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();

            // ... others

            app.UseHangfireDashboard();
            app.UseHangfireServer();
        }
    }
}
